package com.ubing.boot.notesforjava.utils;

import java.lang.reflect.Field;
import java.time.LocalDateTime;

/**
 * @ClassName : CommonUtils
 * @Description : CommonUtils
 * @Author : ubing
 * @Date: 2023-03-25 10:57
 */
public class CommonUtils {

    /***
    * @Title: setCommon
    * @Param: [object]
    * @description:  减少多次重复的代码
    * @author: ubing
    * @date:  10:58
    * @return: void
    * @throws:
    */
    public static void setCommon(Object object) {
        try {
            Class<?> aClass = object.getClass();
            Field userStat = aClass.getDeclaredField("userStat");
            userStat.setAccessible(true);
            userStat.set(object, 1);
            Field updateTime = aClass.getDeclaredField("updateTime");
            updateTime.setAccessible(true);
            updateTime.set(object, LocalDateTime.now());
            Field createTime = aClass.getDeclaredField("createTime");
            createTime.setAccessible(true);
            createTime.set(object, LocalDateTime.now());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
